﻿<Table DataSource="@data" TItem="Data" OnExpand="OnRowExpand">
  <ColumnDefinitions>
    <PropertyColumn Property="c=>c.Name" />
    <PropertyColumn Property="c=>c.Platform" />
    <PropertyColumn Property="c=>c.Version" />
    <PropertyColumn Property="c=>c.UpgradeNum" />
    <PropertyColumn Property="c=>c.Creator" />
    <PropertyColumn Property="c=>c.CreatedAt" />
    <ActionColumn Title="Action"> <a>Publish</a> </ActionColumn>
  </ColumnDefinitions>
  <ExpandTemplate Context="rowData">
    <Table DataSource="rowData.Data.NestedData" Loading="rowData.Data.NestedData==null" HidePagination>
      <PropertyColumn Property="c=>c.Date" />
      <PropertyColumn Property="c=>c.Name" />
      <Column TData="string" Title="Status">
        <span>
          <Badge Status="BadgeStatus.Success" />
          Finished
        </span>
      </Column>
      <PropertyColumn Property="c=>c.UpgradeNum" />
      <ActionColumn Title="Action">
        <Space Size="SpaceSize.Middle">
          <SpaceItem><a>Pause</a></SpaceItem>
          <SpaceItem><a>Stop</a></SpaceItem>
          <SpaceItem>
            <Dropdown Overlay="menu">
              <a>More <Icon Type="@IconType.Outline.Down" /></a>
            </Dropdown>
          </SpaceItem>
        </Space>
      </ActionColumn>
    </Table>
  </ExpandTemplate>
</Table>

@using AntDesign.TableModels
@using System.ComponentModel
@code {

  RenderFragment menu =
    @<Menu>
      <MenuItem>Action 1</MenuItem>
      <MenuItem>Action 2</MenuItem>
    </Menu>;

  Data[] data;

  protected override void OnInitialized()
  {
    base.OnInitialized();

    data = Enumerable.Range(0, 3).Select(x => new Data
      {
        Name = "Screem",
        Platform = "iOS",
        Version = "10.3.4.5654",
        UpgradeNum = 500,
        Creator = "Jack",
        CreatedAt = DateTime.Parse("2014-12-24 23:12:00")
      }).ToArray();
  }

  async Task OnRowExpand(RowData<Data> rowData)
  {
    if (rowData.Data.NestedData != null)
    {
      return;
    }

    await Task.Delay(1000);
    rowData.Data.NestedData = Enumerable.Range(0, 3).Select(i => new NestedData()
      {
        Key = i,
        Date = DateTime.Parse("2014-12-24 23:12:00"),
        Name = "This is production name",
        UpgradeNum = "Upgraded: 56"
      }).ToArray();

    StateHasChanged();
  }

  public class Data
  {
    public string Name { get; set; }
    public string Platform { get; set; }
    public string Version { get; set; }
    [DisplayName("Upgraded")]
    public int UpgradeNum { get; set; }
    public string Creator { get; set; }
    public DateTime CreatedAt { get; set; }

    public NestedData[] NestedData { get; set; }
  }

  public class NestedData
  {
    public int Key { get; set; }
    public DateTime Date { get; set; }
    public string Name { get; set; }
    [DisplayName("Upgrade Status")]
    public string UpgradeNum { get; set; }
  }
}